home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / ScreenSavers / BackSpaceViews / AlarmView.BackModule / Alarm.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  156 lines

  1. /*
  2.  * Alarm.m
  3.  */
  4.  
  5. #import <stdio.h>
  6. #import "Alarm.h"
  7.  
  8. const char *months[] = {"","January","February","March","April","May","June","July","August","September","October","November","December"};
  9.  
  10. @implementation Alarm
  11.  
  12. - resetRinger
  13. {
  14.     gettimeofday(&tv,NULL);
  15.     ringtime = tv.tv_sec;
  16.     return self;
  17. }
  18.  
  19. - findCurrentTime
  20. {
  21.     gettimeofday (&tv,NULL);
  22.     localt = localtime(&tv.tv_sec);
  23.     sec = localt->tm_sec;
  24.     min = localt->tm_min;
  25.     hour = localt->tm_hour;
  26.     day = localt->tm_mday;
  27.     month = localt->tm_mon;
  28.     year = localt->tm_year;
  29.     if (hour > 12)
  30.         pm = YES;
  31.     if (ringing)
  32.     {
  33.         [delegate alarm:self];
  34.         if (tv.tv_sec - ringtime > 10 * 60) // 10 minutes
  35.             ringing = NO;
  36.     } 
  37.     else if (alarmset && delegate && (hour == ahour) && (min == amin))
  38.     {
  39.         ringtime = tv.tv_sec;
  40.         ringing = YES;
  41.         [delegate alarm:self];
  42.     }
  43.     return self;
  44. }
  45.  
  46. - (const char *)timeString
  47. {
  48.     [self findCurrentTime];
  49.     if (hour == 0)
  50.         hour = 12;        
  51.     if (hour > 12)
  52.     {
  53.         hour -= 12;
  54.         sprintf (timestring,"% 2d:%.2d:%.2d PM",
  55.             hour,min,sec);
  56.     } else  sprintf (timestring,"% 2d:%.2d:%.2d AM",
  57.             hour,min,sec);
  58.     return (const char *)timestring;
  59. }
  60.  
  61. - (const char *)militaryTimeString
  62. {
  63.     [self findCurrentTime];
  64.     sprintf (timestring,"% 2d:%2d:%2d",hour,min,sec);
  65.     return (const char *)timestring;
  66. }
  67.  
  68. - (const char *)monthString:(int) i
  69. {
  70.     [self findCurrentTime];
  71.     return months[i];
  72. }
  73.  
  74. - (const char *)dateString
  75. {
  76.     [self findCurrentTime];
  77.     sprintf (timestring,"%s %d, %d",[self monthString:month],day,year);
  78.     return timestring;
  79. }
  80.  
  81.  
  82. - (int)year
  83. {
  84.     [self findCurrentTime];
  85.     return year;
  86. }
  87.  
  88. - (int)month
  89. {
  90.     [self findCurrentTime];
  91.     return month;
  92. }
  93.  
  94. - (int)day
  95. {
  96.     [self findCurrentTime];
  97.     return day;
  98. }
  99.  
  100. - (int)hour
  101. {
  102.     [self findCurrentTime];
  103.     return hour;
  104. }
  105.  
  106.  
  107. - (int)minute
  108. {
  109.     [self findCurrentTime];
  110.     return min;
  111. }
  112.  
  113.  
  114. - (int)second
  115. {
  116.     [self findCurrentTime];
  117.     return sec;
  118. }
  119.  
  120. - setDelegate:sender
  121. {
  122.     delegate = sender;
  123.     return self;
  124. }
  125.  
  126. - setAlarmTime:(int)ah :(int)am
  127. {
  128.     ahour = ah;
  129.     amin = am;
  130.     return self;
  131. }
  132.  
  133. - setAlarmState:(BOOL)astate
  134. {
  135.     alarmset = astate;
  136.     if (!astate)
  137.         ringing = NO;
  138.     return self;
  139. }
  140.  
  141. - (int)alarmHour
  142. {
  143.     return ahour;
  144. }
  145.  
  146. - (int)alarmMinute
  147. {
  148.     return amin;
  149. }
  150.  
  151. - (BOOL)alarmState
  152. {
  153.     return alarmset;
  154. }
  155.  
  156. @end;